<template>
  <div class="profile-top">
    <div class="top">
      <div class="head">
        <img v-if="isShow" :src="userDetail.userhead" alt="">
        <img v-else src="../../../assets/img/profile/head.svg" alt="">
      </div>
      <div class="font">
        <p v-if="isShow">{{userDetail.username}}</p>
        <p v-else>登录立享手机电脑多端同步</p>
      </div>
      <div class="login" @click="login" v-if="!isShow">
        <p>立即登录</p>
      </div>
    </div>
    <div class="bottom">
      <div class="bottom-item" v-for="(item,index) in item" :key="index" @click="choose(index)">
        <img :src="item.src" alt="">
        <p>{{item.font}}</p>
      </div>
    </div>
  </div>
</template>

<script>
    export default {
        name: "ProfileTop",
        data(){
            return{
                item:[
                    {src:require('../../../assets/img/profile/music.svg'),font:'本地音乐'},
                    {src:require('../../../assets/img/profile/download.svg'),font:'下载管理'},
                    {src:require('../../../assets/img/profile/radio.svg'),font:'我的电台'},
                    {src:require('../../../assets/img/profile/collect.svg'),font:'我的收藏'},
                    {src:require('../../../assets/img/profile/song.svg'),font:'关注新歌'},
                ],
                userDetail:{},
                isShow:false
            }
        },
        methods:{
            choose(index){
                switch (index) {
                    case 0:
                        this.$toast.show("该功能暂未开放")
                        break;
                    case 1:
                        this.$toast.show("该功能暂未开放")
                        break;
                    case 2:
                        this.$router.push('/radio')
                        break;
                    case 3:
                        this.$router.push('/mycollect')
                        break;
                    case 4:
                        this.$toast.show("该功能暂未开放")
                        break;
                    default:
                }
            },
            login(){
                this.$router.push('/login')
            }
        },
        created() {
          var type = typeof this.$store.state.userInfo
            if(type == 'object'){
                this.userDetail = this.$store.state.userInfo
                var len =Object.keys(this.$store.state.userInfo).length
                if(len){
                    this.isShow = true
                }
            }else{
                if(this.$store.state.userInfo.length !== 0){
                    this.userDetail = JSON.parse(this.$store.state.userInfo)
                    this.isShow = true
                }
            }
        },


    }
</script>

<style scoped>
  .profile-top{
    background-color: #1E1E24;
    height: 160px;
    position: relative;
    color: white;
    letter-spacing: 1px;
    z-index: 1;
  }

  .top{
    position: absolute;
    display: flex;
    width: 100%;
    margin-top: 15px;
  }

  .head{
    background-color: #CECECE;
    width: 40px;
    height: 40px;
    border-radius: 20px;
    margin-left: 15px;
  }

  .head img{
    width: 100%;
    border-radius: 50%;
  }

  .font{
    line-height: 40px;
    margin-left: 15px;
    flex: 3;
  }

  .font p{
    color: white;
    font-size: 16px;
  }

  .login{
    line-height: 30px;
    width: 70px;
    text-align: center;
    border: 2px solid #45454E;
    border-radius: 15px;
    height: 30px;
    margin-right: 15px;
  }

  .login p{
    color: white;
    font-size: 13px;
  }

  .bottom{
    bottom: 35px;
    position: absolute;
    width: 100%;
    height: 50px;
    display: flex;
    text-align: center;
  }

  .bottom-item{
    flex: 1;
  }

  .bottom-item img{
    width: 25px;
    height: 25px;
    margin-bottom: 5px;
  }

  .bottom-item p{
    font-size: 12px;
  }


</style>